package org.infosec.lc.exercises.stringUtils;

import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringSplitUtils {

	public static void main(String[] args) {
		String str = "[Type=UPC-A][Final=10][Nnmber=9]";
//		String str = "[Type=UPC-A]";
		
		//util分词器
//		Tokenizer(str);
//		String[] strArr = str.split("(?<=\\])(?=\\[)");  
		
		String aa = "acount=a and uu =b or n=c";
		String[] a = aa.split("and|or");
		for(String s:a)
			System.out.println(s);
		String[] strArr = str.split("\\[|]");  
		System.out.println(strArr.length);
		for(String s:strArr)
			System.out.println(s);
		//
		System.out.println(str.intern());
		Pattern pattern = Pattern.compile("\\[(.*)]");
//		Pattern pattern = Pattern.compile("\\[([^=]*)=([^]]*)\\]");
		Matcher matcher = pattern.matcher(str);
		
		if(matcher.find()){
			System.out.println(matcher.groupCount());
			for(int i=1;i<=matcher.groupCount();i++){
				System.out.println(matcher.group(i));
			}
		}
	}
	
	/**
	 * java.util.StringTokenizer 分词器
	 * @param str
	 */
	private static void Tokenizer(String str) {
		StringTokenizer stk = new StringTokenizer(str, "[=]");
		System.out.println(stk.countTokens());
		while (stk.hasMoreElements()) {
			System.out.println(stk.nextElement());
		}
	}
}
